home *** CD-ROM | disk | FTP | other *** search
/ 3D GFX / 3D GFX.iso / amiutils / i_l / irit5 / grapdrvs / xogldrvs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-31  |  35.5 KB  |  1,111 lines

  1. /*****************************************************************************
  2. *   An SGI 4D driver using Open GL.                         *
  3. *                                         *
  4. * Written by:  Gershon Elber                 Ver 0.1, October 1994.  *
  5. *****************************************************************************/
  6.  
  7. #include <X11/Xlib.h>
  8. #include <X11/Xutil.h>
  9. #include <X11/cursorfont.h>
  10. #include <X11/Xresource.h>
  11.  
  12. #include <GL/glx.h>
  13. #include <GL/gl.h>
  14. #include <unistd.h>
  15.  
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <math.h>
  19. #include <ctype.h>
  20. #ifdef _AIX
  21. #    include <fcntl.h>
  22. #else
  23. #    include <sys/fcntl.h>
  24. #endif
  25. #include "irit_sm.h"
  26. #include "genmat.h"
  27. #include "iritprsr.h"
  28. #include "allocate.h"
  29. #include "attribut.h"
  30. #include "ip_cnvrt.h"
  31. #include "cagd_lib.h"
  32. #include "symb_lib.h"
  33. #include "iritgrap.h"
  34.  
  35. /* Interactive menu setup structure: */
  36. #define INTERACT_NUM_OF_STRINGS        4
  37. #define INTERACT_NUM_OF_SUB_WNDWS    16
  38.  
  39. typedef struct InteractString {
  40.     RealType X, Y;
  41.     int Color;
  42.     char *Str;
  43. } InteractString;
  44. typedef struct InteractSubWindow {
  45.     RealType X, Y;                       /* Center points. */
  46.     int Color;
  47.     IGGraphicEventType Event;
  48.     int TextInside; /* If TRUE, Str will be in window, otherwise left to it. */
  49.     char *Str;
  50. } InteractSubWindow;
  51. typedef struct InteractWindowStruct {     /* The interactive menu structures. */
  52.     /* Rotate, Translate, Scale strings: */
  53.     InteractString Strings[INTERACT_NUM_OF_STRINGS];
  54.     InteractSubWindow SubWindows[INTERACT_NUM_OF_SUB_WNDWS];
  55. } InteractWindowStruct;
  56.  
  57. #define INTERACT_SUB_WINDOW_WIDTH  0.8         /* Relative to window size. */
  58. #define INTERACT_SUB_WINDOW_HEIGHT 0.04
  59.  
  60. static int
  61.     GlblStateMenu = 0;
  62.  
  63. static long
  64.     TransWinWidth = 100,
  65.     TransWinWidth2 = 50,
  66.     TransWinHeight = 100,
  67.     TransWinLow = 0,
  68.     TransWinLeft = 0,
  69.     ViewWinWidth = 100,
  70.     ViewWinWidth2 = 50,
  71.     ViewWinHeight = 100,
  72.     ViewWinHeight2 = 50,
  73.     ViewWinLow = 0,
  74.     ViewWinLeft = 0;
  75.  
  76. static GLXContext ViewCx, TransCx;
  77. static Display *XDisplay;
  78. static Window ViewWin, TransWin,
  79.     ObjScrTglWndw, PersOrthoTglWndw, PersOrthoZWndw,
  80.     RotateXWndw, RotateYWndw, RotateZWndw, TranslateXWndw,
  81.     TranslateYWndw, TranslateZWndw, ScaleWndw, DepthCueWndw,
  82.     SaveMatrixWndw, PushMatrixWndw, PopMatrixWndw, QuitWndw;
  83.  
  84. /* Interactive mode menu set up structure is define below: */
  85. static InteractWindowStruct InteractMenu = {
  86.     { { 0.5, 0.81, IG_IRIT_RED,        "Rotate" },
  87.       { 0.5, 0.65, IG_IRIT_GREEN,    "Translate" },
  88.       { 0.5, 0.49, IG_IRIT_CYAN,    "Scale" },
  89.       { 0.5, 0.41, IG_IRIT_LIGHTGREEN,    "Clip Plane" },
  90.     },
  91.     { { 0.5, 0.93, IG_IRIT_YELLOW, IG_EVENT_SCR_OBJ_TGL,    TRUE,  "Screen Coords." },
  92.       { 0.5, 0.87, IG_IRIT_BLUE,   IG_EVENT_PERS_ORTHO_TGL,TRUE,  "Perspective" },
  93.       { 0.5, 0.83, IG_IRIT_BLUE,   IG_EVENT_PERS_ORTHO_Z,    FALSE, "Z" },
  94.       { 0.5, 0.75, IG_IRIT_RED,    IG_EVENT_ROTATE_X,        FALSE, "X" }, /* Rot */
  95.       { 0.5, 0.71, IG_IRIT_RED,    IG_EVENT_ROTATE_Y,        FALSE, "Y" },
  96.       { 0.5, 0.67, IG_IRIT_RED,    IG_EVENT_ROTATE_Z,        FALSE, "Z" },
  97.       { 0.5, 0.59, IG_IRIT_GREEN,  IG_EVENT_TRANSLATE_X,    FALSE, "X" }, /* Trans */
  98.       { 0.5, 0.55, IG_IRIT_GREEN,  IG_EVENT_TRANSLATE_Y,    FALSE, "Y" },
  99.       { 0.5, 0.51, IG_IRIT_GREEN,  IG_EVENT_TRANSLATE_Z,    FALSE, "Z" },
  100.       { 0.5, 0.43, IG_IRIT_CYAN,   IG_EVENT_SCALE,        FALSE, "" },  /* Scale */
  101.       { 0.5, 0.35, IG_IRIT_LIGHTGREEN, IG_EVENT_NEAR_CLIP,    FALSE,  "" },
  102.       { 0.5, 0.31, IG_IRIT_LIGHTGREEN, IG_EVENT_FAR_CLIP,    FALSE,  "" },
  103.  
  104.       { 0.5, 0.20, IG_IRIT_YELLOW, IG_EVENT_SAVE_MATRIX,    TRUE,  "Save Matrix" },
  105.       { 0.5, 0.13, IG_IRIT_YELLOW, IG_EVENT_PUSH_MATRIX,    TRUE,  "Push Matrix" },
  106.       { 0.5, 0.09, IG_IRIT_YELLOW, IG_EVENT_POP_MATRIX,        TRUE,  "Pop Matrix" },
  107.       { 0.5, 0.03, IG_IRIT_WHITE,  IG_EVENT_QUIT,        TRUE,  "Quit" },
  108.     }
  109. };
  110.  
  111. static short Colors[IG_MAX_COLOR + 1][3] =
  112. {
  113.     { 0,   0,   0   },  /* 0. BLACK */
  114.     { 0,   0,   170 },  /* 1. BLUE */
  115.     { 0,   170, 0   },  /* 2. GREEN */
  116.     { 0,   170, 170 },  /* 3. CYAN */
  117.     { 170, 0,   0   },  /* 4. RED */
  118.     { 170, 0,   170 },  /* 5. MAGENTA */
  119.     { 170, 170, 0   },  /* 6. BROWN */
  120.     { 170, 170, 170 },  /* 7. LIGHTGREY */
  121.     { 85,  85,  85  },  /* 8. DARKGRAY */
  122.     { 85,  85,  255 },  /* 9. LIGHTBLUE */
  123.     { 85,  255, 85  },  /* 10. LIGHTGREEN */
  124.     { 85,  255, 255 },  /* 11. LIGHTCYAN */
  125.     { 255, 85,  85  },  /* 12. LIGHTRED */
  126.     { 255, 85,  255 },  /* 13. LIGHTMAGENTA */
  127.     { 255, 255, 85  },  /* 14. YELLOW */
  128.     { 255, 255, 255 }   /* 15. WHITE */
  129. };
  130.  
  131. static void SetColorIndex(int c);
  132. static void SetColorRGB(int Color[3]);
  133. static void ClearViewArea(void);
  134. static void SetTransformWindow(int argc, cahr **argv);
  135. static void RedrawTransformWindow(void);
  136. static void SetViewWindow(void);
  137. static IGGraphicEventType GetGraphicEvent(RealType *ChangeFactor);
  138. static void DrawText(char *Str, long PosX, long PosY);
  139.  
  140. /****************************************************************************
  141. * Pop up all windows, read input and display.                    *
  142. ****************************************************************************/
  143. void main(int argc, char **argv)
  144. {
  145.     RealType ChangeFactor;
  146.     IGGraphicEventType Event;
  147.     IPObjectStruct *PObjects;
  148.  
  149.     IGConfigureGlobals("xogldrvs", argc, argv);
  150.  
  151.     XDisplay = XOpenDisplay(0);
  152.  
  153.     SetViewWindow();
  154.     IGRedrawViewWindow();
  155.     SetTransformWindow(argc, argv);
  156.     RedrawTransformWindow();
  157.  
  158.     IGCreateStateMenu();
  159.  
  160.     while ((Event = GetGraphicEvent(&ChangeFactor)) != IG_EVENT_QUIT) {
  161.     if (IGProcessEvent(Event, ChangeFactor * IGGlblChangeFactor))
  162.         IGRedrawViewWindow();
  163.     }
  164. }
  165.  
  166. /*****************************************************************************
  167. * Construct global pop up menu.                             *
  168. *****************************************************************************/
  169. void IGCreateStateMenu(void)
  170. {
  171. #ifdef TTTTT
  172.     if (GlblStateMenu) 
  173.         freepup(GlblStateMenu);
  174.  
  175.     GlblStateMenu = newpup();
  176.  
  177.     addtopup(GlblStateMenu, " Set Up %t", 0);
  178.     addtopup(GlblStateMenu, "Oops!%l", 0);
  179.     addtopup(GlblStateMenu, "More Sensitive", 0);
  180.     addtopup(GlblStateMenu, "Less Sensitive%l", 0);
  181.     addtopup(GlblStateMenu, IGGlblTransformMode == IG_TRANS_SCREEN ?
  182.                 "Screen Trans." : "Object Trans", 0);
  183.     addtopup(GlblStateMenu, IGGlblViewMode == IG_VIEW_PERSPECTIVE ?
  184.                 "Perspective" : "Orthographic", 0);
  185.     addtopup(GlblStateMenu,
  186.          IGGlblDepthCue ? "Depth Cue" : "No Depth Cue", 0);
  187.     addtopup(GlblStateMenu,
  188.          IGGlblDrawSolid ? "Draw Solid" : "Draw Wireframe", 0);
  189.     addtopup(GlblStateMenu,
  190.          IGGlblDoDoubleBuffer ? "Double Buffer" : "Single Buffer", 0);
  191.     addtopup(GlblStateMenu,
  192.          IGGlblAntiAliasing ? "Anti Aliasing" : "No Anti Aliasing", 0);
  193.     addtopup(GlblStateMenu,
  194.          IGGlblDrawInternal ? "Draw Internal Edges" : "No Internal Edges", 0);
  195.     addtopup(GlblStateMenu,
  196.          IGGlblDrawVNormal ? "Draw Vrtx Normals" :  "No Vrtx Normals", 0);
  197.     addtopup(GlblStateMenu,
  198.          IGGlblDrawPNormal ? "Draw Poly Normals" :  "No Poly Normals", 0);
  199.     addtopup(GlblStateMenu,
  200.          IGGlblDrawSurfaceMesh ? "Draw Surface Mesh" : "No Surface Mesh", 0);
  201.     addtopup(GlblStateMenu,
  202.          IGGlblDrawSurfacePoly ? "Surface Polygons" : "Surface Isolines", 0);
  203.     addtopup(GlblStateMenu,
  204.          IGGlblFourPerFlat ? "Four Per Flat%l" : "Two Per Flat%l", 0);
  205.     addtopup(GlblStateMenu, "More Isolines", 0);
  206.     addtopup(GlblStateMenu, "Less Isolines%l", 0);
  207.     addtopup(GlblStateMenu, "Finer approx.", 0);
  208.     addtopup(GlblStateMenu, "Coarser approx.%l", 0);
  209.     addtopup(GlblStateMenu, "Longer Vectors.", 0);
  210.     addtopup(GlblStateMenu, "Shorter Vectors", 0);
  211.     addtopup(GlblStateMenu, "Wider Lines", 0);
  212.     addtopup(GlblStateMenu, "Narrow Lines", 0);
  213.     addtopup(GlblStateMenu, "Front View", 0);
  214.     addtopup(GlblStateMenu, "Size View", 0);
  215.     addtopup(GlblStateMenu, "Top View", 0);
  216.     addtopup(GlblStateMenu, "Isometry View", 0);
  217.     addtopup(GlblStateMenu, "Clear View Area", 0);
  218. #endif
  219. }
  220.  
  221. /****************************************************************************
  222. * Draw a Point/Vector object using current modes and transformations.        *
  223. ****************************************************************************/
  224. void IGDrawPtVec(IPObjectStruct *PObj)
  225. {
  226.     int i;
  227.     PointType Ends[6], Zero;
  228.     RealType
  229.     *Pt = PObj -> U.Pt;
  230.  
  231.     for (i = 0; i < 6; i++)
  232.     PT_COPY(Ends[i], Pt);
  233.  
  234.     Ends[0][0] -= IG_POINT_WIDTH;
  235.     Ends[1][0] += IG_POINT_WIDTH;
  236.     Ends[2][1] -= IG_POINT_WIDTH;
  237.     Ends[3][1] += IG_POINT_WIDTH;
  238.     Ends[4][2] -= IG_POINT_WIDTH;
  239.     Ends[5][2] += IG_POINT_WIDTH;
  240.  
  241.     for (i = 0; i < 6; i += 2) {
  242.     glBegin(GL_LINES);
  243.     glVertex3dv(Ends[i]);
  244.     glVertex3dv(Ends[i+1]);
  245.     glEnd();
  246.     }
  247.  
  248.     if (IP_IS_VEC_OBJ(PObj)) {
  249.     glBegin(GL_LINES);
  250.     glVertex3dv(Pt);
  251.     Zero[0] = Zero[1] = Zero[2] = 0.0;
  252.     glVertex3dv(Zero);
  253.     glEnd();
  254.     }
  255. }
  256.  
  257. /****************************************************************************
  258. * Draw a Poly object using current modes and transformations.            *
  259. ****************************************************************************/
  260. void IGDrawPoly(IPObjectStruct *PObj)
  261. {
  262.     IPVertexStruct *V;
  263.     IPPolygonStruct
  264.     *Pl = PObj -> U.Pl;
  265.  
  266.     if (IP_IS_POLYLINE_OBJ(PObj)) {
  267.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  268.         glBegin(GL_LINE_STRIP);
  269.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext)
  270.             glVertex3dv(V -> Coord);
  271.         glEnd();
  272.     }
  273.     }
  274.     else if (IP_IS_POINTLIST_OBJ(PObj)) {
  275.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  276.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  277.         int i;
  278.         PointType Ends[6];
  279.         RealType
  280.             *Pt = V -> Coord;
  281.  
  282.         for (i = 0; i < 6; i++)
  283.             PT_COPY(Ends[i], Pt);
  284.  
  285.         Ends[0][0] -= IG_POINT_WIDTH;
  286.         Ends[1][0] += IG_POINT_WIDTH;
  287.         Ends[2][1] -= IG_POINT_WIDTH;
  288.         Ends[3][1] += IG_POINT_WIDTH;
  289.         Ends[4][2] -= IG_POINT_WIDTH;
  290.         Ends[5][2] += IG_POINT_WIDTH;
  291.  
  292.         for (i = 0; i < 6; i += 2) {
  293.             glBegin(GL_LINES);
  294.             glVertex3dv(Ends[i]);
  295.             glVertex3dv(Ends[i+1]);
  296.             glEnd();
  297.         }
  298.         }
  299.     }
  300.     }
  301.     else if (IP_IS_POLYGON_OBJ(PObj)) {
  302.     int i, j,
  303.         NumOfVertices;
  304.     PointType PNormal, VNormal;
  305.  
  306.     for (; Pl != NULL; Pl = Pl -> Pnext) {
  307.         if (IGGlblDrawPNormal) {
  308.         NumOfVertices = 0;
  309.         PNormal[0] = PNormal[1] = PNormal[2] = 0.0;
  310.         }
  311.  
  312.         if (IGGlblDrawSolid) {
  313.         glBegin(GL_POLYGON);
  314.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  315.             glNormal3dv(V -> Normal);
  316.             glVertex3dv(V -> Coord);
  317.  
  318.             if (IGGlblDrawPNormal) {
  319.             for (j = 0; j < 3; j++)
  320.                 PNormal[j] += V -> Coord[j];
  321.             NumOfVertices++;
  322.             }
  323.         }
  324.         glEnd();
  325.         }
  326.         else {
  327.         glBegin(GL_LINES);
  328.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  329.             glVertex3dv(V -> Coord);
  330.             if (IP_IS_INTERNAL_VRTX(V) && !IGGlblDrawInternal) {
  331.             glEnd();
  332.             glBegin(GL_LINE_STRIP);
  333.             }
  334.  
  335.             if (IGGlblDrawPNormal) {
  336.             for (j = 0; j < 3; j++)
  337.                 PNormal[j] += V -> Coord[j];
  338.             NumOfVertices++;
  339.             }
  340.         }
  341.         glVertex3dv(Pl -> PVertex -> Coord);
  342.         glEnd();
  343.         }
  344.  
  345.         if (IGGlblDrawPNormal && IP_HAS_PLANE_POLY(Pl)) {
  346.         glBegin(GL_LINES);
  347.         for (i = 0; i < 3; i++)
  348.             PNormal[i] /= NumOfVertices;
  349.         glVertex3dv(PNormal);
  350.         for (i = 0; i < 3; i++)
  351.             PNormal[i] += Pl -> Plane[i] * IGGlblNormalLen;
  352.         glVertex3dv(PNormal);
  353.         glEnd();
  354.         }
  355.  
  356.         if (IGGlblDrawVNormal) {
  357.         for (V = Pl -> PVertex; V != NULL; V = V -> Pnext) {
  358.             if (IP_HAS_NORMAL_VRTX(V)) {
  359.             for (j = 0; j < 3; j++)
  360.                 VNormal[j] = V -> Coord[j] +
  361.                          V -> Normal[j] * IGGlblNormalLen;
  362.             glBegin(GL_LINES);
  363.             glVertex3dv(V ->Coord);
  364.             glVertex3dv(VNormal);
  365.             glEnd();
  366.             }
  367.         }
  368.         }
  369.     }
  370.     }
  371. }
  372.  
  373. /****************************************************************************
  374. * Routine to set the color according to the given object's color.        *
  375. ****************************************************************************/
  376. void IGSetColorObj(IPObjectStruct *PObj)
  377. {
  378.     int c, Color[3];
  379.  
  380.     if (AttrGetObjectRGBColor(PObj, &Color[0], &Color[1], &Color[2])) {
  381.     SetColorRGB(Color);
  382.     }
  383.     else if ((c = AttrGetObjectColor(PObj)) != IP_ATTR_NO_COLOR) {
  384.     SetColorIndex(c);
  385.     }
  386.     else {
  387.     /* Use white as default color: */
  388.     SetColorIndex(IG_IRIT_WHITE);
  389.     }
  390. }
  391.  
  392. /****************************************************************************
  393. * Routine to set the line width to draw the given object, in pixels.        *
  394. ****************************************************************************/
  395. void IGSetWidthObj(int Width)
  396. {
  397.     glLineWidth(Width);
  398. }
  399.  
  400. /****************************************************************************
  401. * Routine to set the color according to the given color index.            *
  402. ****************************************************************************/
  403. static void SetColorIndex(int c)
  404. {
  405.     int Color[3];
  406.  
  407.     if (c < 0 || c > IG_MAX_COLOR)
  408.         c = IG_IRIT_WHITE;
  409.  
  410.     Color[0] = Colors[c][0];
  411.     Color[1] = Colors[c][1];
  412.     Color[2] = Colors[c][2];
  413.  
  414.     SetColorRGB(Color);
  415. }
  416.  
  417. /****************************************************************************
  418. * Routine to set the color according to the given RGB values.            *
  419. ****************************************************************************/
  420. static void SetColorRGB(int Color[3])
  421. {
  422.     int i;
  423.  
  424.     if (IGGlblDrawSolid) {
  425.     GLfloat MatAmbient[4], MatDiffuse[4], MatSpecular[4];
  426.     static GLfloat
  427.         MatShininess[] = { 15.0 };
  428.  
  429.     for (i = 0; i < 3; i++) {
  430.         MatAmbient[i] = 0.2 * Color[0] / 255.0;
  431.         MatDiffuse[i] = 0.4 * Color[i] / 255.0;
  432.         MatSpecular[i] = Color[i] / 255.0;
  433.     }
  434.     MatAmbient[3] = MatDiffuse[3] = MatSpecular[3] = 1.0;
  435.  
  436.     glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, MatAmbient);
  437.     glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MatDiffuse);
  438.     glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, MatSpecular);
  439.     glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, MatShininess);
  440.     }
  441.     else
  442.     glColor3f(Color[0] / 255.0, Color[1] / 255.0, Color[2] / 255.0);
  443.  
  444.     if (IGGlblDepthCue) {
  445.     GLfloat fogColor[4];
  446.  
  447.     for (i = 0; i < 3; i++)
  448.         fogColor[i] = (float) IGGlblBackGroundColor[i] / 255.0;
  449.     fogColor[3] = (float) 1.0;
  450.  
  451.     glEnable(GL_FOG);
  452.     glFogi(GL_FOG_MODE, GL_LINEAR);
  453.     glHint(GL_FOG_HINT, GL_NICEST);
  454.     glFogf(GL_FOG_START, (float) IGGlblZMinClip);
  455.     glFogf(GL_FOG_END, (float) IGGlblZMaxClip);
  456.     glFogfv(GL_FOG_COLOR, fogColor);
  457.     }
  458.     else
  459.     glDisable(GL_FOG);
  460. }
  461.  
  462. /*****************************************************************************
  463. * Set up and draw a transformation window.                     *
  464. *****************************************************************************/
  465. static void SetTransformWindow(int argc, char **argv)
  466. {
  467.     int SubTransPosX, SubTransPosY, SubTransWidth, SubTransHeight;
  468.     long ValueMask;
  469.     XSizeHints Hints;
  470.     XSetWindowAttributes SetWinAttr;
  471.  
  472.     SetWinAttr.background_pixel = TransBackGroundPixel;
  473.     SetWinAttr.border_pixel = TransBorderPixel;
  474.     ValueMask = CWBackPixel | CWBorderPixel;
  475.  
  476.     Hints.flags = PMinSize | PMaxSize;
  477.     Hints.x = Hints.y = 1;
  478.     Hints.min_width = 100;
  479.     Hints.max_width = 1000;
  480.     Hints.min_height = 200;
  481.     Hints.max_height = 1000;
  482.     if (TransHasSize) {
  483.     Hints.flags |= PSize;
  484.     if (TransWidth < Hints.min_width)
  485.         TransWidth = Hints.min_width;
  486.     if (TransWidth > Hints.max_width)
  487.         TransWidth = Hints.max_width;
  488.     if (TransHeight < Hints.min_height)
  489.         TransHeight = Hints.min_height;
  490.     if (TransHeight > Hints.max_height)
  491.         TransHeight = Hints.max_height;
  492.     Hints.width = TransWidth;
  493.     Hints.height = TransHeight;
  494.     }
  495.     else {
  496.     Hints.flags |= PSize;
  497.     Hints.width = TransWidth = DEFAULT_TRANS_WIDTH;
  498.     Hints.height = TransHeight = DEFAULT_TRANS_HEIGHT;
  499.     }
  500.     if (TransHasPos) {
  501.     Hints.flags |= USPosition;
  502.     Hints.x = TransPosX;
  503.     Hints.y = TransPosY;
  504.     }
  505.  
  506.     TransformWndw = XCreateWindow(XDisplay, XRoot,
  507.                   TransPosX, TransPosY,
  508.                   TransWidth, TransHeight,
  509.                       1, 0, CopyFromParent, CopyFromParent,
  510.                       ValueMask, &SetWinAttr);
  511.  
  512.     XSetStandardProperties(XDisplay, TransformWndw,
  513.                RESOURCE_NAME, RESOURCE_NAME, None,
  514.                argv, argc,
  515.                &Hints);
  516.  
  517.     /* Set our own cursor: */
  518.     XCursor = XCreateFontCursor(XDisplay, XC_hand1);
  519.     XDefineCursor(XDisplay, TransformWndw, XCursor);
  520.     if (TransCursorColor != NULL)
  521.     XRecolorCursor(XDisplay, XCursor, TransCursorColor, &BlackColor);
  522.  
  523.     /* Now lets create the sub windows inside. Note we do not place them yet. */
  524.     SubTransPosX = 0;
  525.     SubTransPosY = TransHeight;
  526.     SubTransWidth = TransWidth - SubTransPosX * 2;
  527.     SubTransHeight = TransHeight / 25;
  528.  
  529.     /* OBJECT/SCREEN space toggle: */
  530.     ObjScrTglWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  531.                       SubTransWidth, SubTransHeight);
  532.  
  533.     /* PERSPECTIVE/ORTHOGRPHIC toggle: */
  534.     PersOrthoTglWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  535.                          SubTransWidth, SubTransHeight);
  536.     PersOrthoZWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  537.                          SubTransWidth, SubTransHeight);
  538.  
  539.     /* ROTATE: */
  540.     RotateXWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  541.                     SubTransWidth, SubTransHeight);
  542.     RotateYWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  543.                     SubTransWidth, SubTransHeight);
  544.     RotateZWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  545.                     SubTransWidth, SubTransHeight);
  546.     /* TRANSLATE: */
  547.     TranslateXWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  548.                        SubTransWidth, SubTransHeight);
  549.     TranslateYWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  550.                        SubTransWidth, SubTransHeight);
  551.     TranslateZWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  552.                        SubTransWidth, SubTransHeight);
  553.     /* SCALE: */
  554.     ScaleWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  555.                       SubTransWidth, SubTransHeight);
  556.  
  557.     /* DEPTH CUE: */
  558.     DepthCueWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  559.                      SubTransWidth, SubTransHeight);
  560.  
  561.     /* SAVE MATRIX: */
  562.     SaveMatrixWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  563.                        SubTransWidth, SubTransHeight);
  564.  
  565.     /* PUSH MATRIX: */
  566.     PushMatrixWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  567.                        SubTransWidth, SubTransHeight);
  568.  
  569.     /* POP MATRIX: */
  570.     PopMatrixWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  571.                       SubTransWidth, SubTransHeight);
  572.  
  573.     /* QUIT: */
  574.     QuitWndw = SetTransformSubWindow(SubTransPosX, SubTransPosY,
  575.                      SubTransWidth, SubTransHeight);
  576.  
  577.     XSelectInput(XDisplay, TransformWndw, ExposureMask);
  578. }
  579.  
  580. /*****************************************************************************
  581. * Redraw a transformation window (after exposure or resize events).         *
  582. *****************************************************************************/
  583. static void RedrawTransformWindow(void)
  584. {
  585.     int SubTransPosX, SubTransPosY,
  586.         SizeChanged = FALSE;
  587.     unsigned long SubTransWidth, SubTransHeight;
  588.     long ValueMask;
  589.     XSizeHints Hints;
  590.     XWindowAttributes TransWindowAttr;
  591.     XSetWindowAttributes SetWinAttr;
  592.  
  593.     XClearWindow(XDisplay, TransformWndw);
  594.  
  595.     /* Get the window attributes, and see if it is the same size or not. */
  596.     XGetWindowAttributes(XDisplay, TransformWndw, &TransWindowAttr);
  597.     if (TransWindowAttr.width != TransWidth ||
  598.     TransWindowAttr.height != TransHeight) {
  599.     SizeChanged = TRUE;
  600.     TransWidth = TransWindowAttr.width;
  601.     TransHeight = TransWindowAttr.height;
  602.     }
  603.  
  604.     /* Now lets update the sub windows inside: */
  605.     SubTransPosX = MIN(TransWidth / 10, 20);
  606.     SubTransPosY =  TransHeight / 28;
  607.     SubTransWidth = TransWidth - SubTransPosX * 2;
  608.     SubTransHeight = TransHeight / 28;
  609.  
  610.     /* OBJECT/SCREEN space toggle: */
  611.     RedrawTransformSubWindow(ObjScrTglWndw, SubTransPosX, SubTransPosY,
  612.                  SubTransWidth, SubTransHeight, FALSE,
  613.                  IGGlblTransformMode == IG_TRANS_OBJECT ?
  614.                  "Object" : "Screen");
  615.     SubTransPosY += SubTransHeight * 2;
  616.  
  617.     /* PERSPECTIVE/ORTHOGRAPHIC toggle: */
  618.     RedrawTransformSubWindow(PersOrthoTglWndw, SubTransPosX, SubTransPosY,
  619.                  SubTransWidth, SubTransHeight, FALSE,
  620.                  IGGlblViewMode == IG_VIEW_ORTHOGRAPHIC ?
  621.                  "Orthographic" : "Perspective");
  622.     SubTransPosY += SubTransHeight;
  623.     RedrawTransformSubWindow(PersOrthoZWndw, SubTransPosX, SubTransPosY,
  624.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  625.     SubTransPosY += SubTransHeight;
  626.     DrawText(TransformWndw, "Z", SubTransPosX / 2,
  627.          SubTransPosY - SubTransHeight / 4, TransTextPixel);
  628.     SubTransPosY += SubTransHeight;
  629.  
  630.     /* ROTATE: */
  631.     DrawText(TransformWndw, "Rotate", TransWidth / 2, SubTransPosY,
  632.          TransTextPixel);
  633.     SubTransPosY += SubTransHeight / 2;
  634.     RedrawTransformSubWindow(RotateXWndw, SubTransPosX, SubTransPosY,
  635.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  636.     SubTransPosY += SubTransHeight;
  637.     DrawText(TransformWndw, "X", SubTransPosX / 2,
  638.          SubTransPosY - SubTransHeight / 4, TransTextPixel);
  639.     RedrawTransformSubWindow(RotateYWndw, SubTransPosX, SubTransPosY,
  640.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  641.     SubTransPosY += SubTransHeight;
  642.     DrawText(TransformWndw, "Y", SubTransPosX / 2,
  643.          SubTransPosY - SubTransHeight / 4, TransTextPixel);
  644.     RedrawTransformSubWindow(RotateZWndw, SubTransPosX, SubTransPosY,
  645.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  646.     SubTransPosY += SubTransHeight;
  647.     DrawText(TransformWndw, "Z", SubTransPosX / 2,
  648.          SubTransPosY - SubTransHeight / 4, TransTextPixel);
  649.  
  650.     /* TRANSLATE: */
  651.     SubTransPosY += SubTransHeight;
  652.     DrawText(TransformWndw, "Translate", TransWidth / 2, SubTransPosY,
  653.          TransTextPixel);
  654.     SubTransPosY += SubTransHeight / 2;
  655.     RedrawTransformSubWindow(TranslateXWndw, SubTransPosX, SubTransPosY,
  656.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  657.     SubTransPosY += SubTransHeight;
  658.     DrawText(TransformWndw, "X", SubTransPosX / 2,
  659.          SubTransPosY - SubTransHeight / 4, TransTextPixel);
  660.     RedrawTransformSubWindow(TranslateYWndw, SubTransPosX, SubTransPosY,
  661.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  662.     SubTransPosY += SubTransHeight;
  663.     DrawText(TransformWndw, "Y", SubTransPosX / 2,
  664.          SubTransPosY - SubTransHeight / 4, TransTextPixel);
  665.     RedrawTransformSubWindow(TranslateZWndw, SubTransPosX, SubTransPosY,
  666.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  667.     SubTransPosY += SubTransHeight;
  668.     DrawText(TransformWndw, "Z", SubTransPosX / 2,
  669.          SubTransPosY - SubTransHeight / 4, TransTextPixel);
  670.  
  671.     /* SCALE: */
  672.     SubTransPosY += SubTransHeight;
  673.     DrawText(TransformWndw, "Scale", TransWidth / 2, SubTransPosY,
  674.          TransTextPixel);
  675.     SubTransPosY += SubTransHeight / 2;
  676.     RedrawTransformSubWindow(ScaleWndw, SubTransPosX, SubTransPosY,
  677.                  SubTransWidth, SubTransHeight, TRUE, NULL);
  678.  
  679.     /* DEPTH CUE: */
  680.     SubTransPosY += SubTransHeight * 2;
  681.     RedrawTransformSubWindow(DepthCueWndw, SubTransPosX, SubTransPosY,
  682.                  SubTransWidth, SubTransHeight, FALSE,
  683.                  IGGlblDepthCue ? "Depth Cue" : "No Depth Cue");
  684.  
  685.     /* SAVE MATRIX: */
  686.     SubTransPosY += SubTransHeight * 2;
  687.     RedrawTransformSubWindow(SaveMatrixWndw, SubTransPosX, SubTransPosY,
  688.                  SubTransWidth, SubTransHeight, FALSE,
  689.                  "Save Matrix");
  690.  
  691.     /* PUSH MATRIX: */
  692.     SubTransPosY += SubTransHeight + SubTransHeight / 2;
  693.     RedrawTransformSubWindow(PushMatrixWndw, SubTransPosX, SubTransPosY,
  694.                  SubTransWidth, SubTransHeight, FALSE,
  695.                  "Push Matrix");
  696.  
  697.     /* POP MATRIX: */
  698.     SubTransPosY += SubTransHeight + SubTransHeight / 2;
  699.     RedrawTransformSubWindow(PopMatrixWndw, SubTransPosX, SubTransPosY,
  700.                  SubTransWidth, SubTransHeight, FALSE,
  701.                  "Pop Matrix");
  702.  
  703.     /* QUIT: */
  704.     SubTransPosY += SubTransHeight * 3;
  705.     RedrawTransformSubWindow(QuitWndw, SubTransPosX, SubTransPosY,
  706.                  SubTransWidth, SubTransHeight, FALSE, "Quit" );
  707.  
  708.     /* Save half of the window width so we can refer to the zero point on X */
  709.     /* axes, which is the vertical line in the middle of the window:        */
  710.     SubWindowWidthState2 = SubTransWidth / 2;
  711.     SubWindowHeightState2 = SubTransHeight / 2;
  712.  
  713.     GraphicFlush();
  714. }
  715.  
  716. /*****************************************************************************
  717. * Set up a transformation sub window.                         *
  718. *****************************************************************************/
  719. static Window SetTransformSubWindow(int SubTransPosX, int SubTransPosY,
  720.             unsigned int SubTransWidth, unsigned int SubTransHeight)
  721. {
  722.     long ValueMask;
  723.     XSetWindowAttributes SetWinAttr;
  724.     Window Win;
  725.  
  726.     SetWinAttr.background_pixel = TransSubWinBackPixel;
  727.     SetWinAttr.border_pixel = TransSubWinBorderPixel;
  728.     SetWinAttr.bit_gravity = SetWinAttr.win_gravity = CenterGravity;
  729.     ValueMask = CWBackPixel | CWBorderPixel | CWBitGravity | CWWinGravity;
  730.  
  731.     Win = XCreateWindow(XDisplay, TransformWndw,
  732.             SubTransPosX, SubTransPosY,
  733.             SubTransWidth, SubTransHeight,
  734.             1, 0, CopyFromParent, CopyFromParent,
  735.             ValueMask, &SetWinAttr);
  736.  
  737.     XSelectInput(XDisplay, Win, ButtonPressMask | Button1MotionMask);
  738.  
  739.     XMapWindow(XDisplay, Win);
  740.  
  741.     return Win;
  742. }
  743.  
  744. /*****************************************************************************
  745. * Redraw a transformation sub window.                         *
  746. *****************************************************************************/
  747. static void RedrawTransformSubWindow(Window Win,
  748.     int SubTransPosX, int SubTransPosY,
  749.     unsigned int SubTransWidth, unsigned int SubTransHeight,
  750.     int DrawMiddleVertLine, char *DrawString)
  751. {
  752.     XGCValues values;
  753.  
  754.     XMoveResizeWindow(XDisplay, Win, SubTransPosX, SubTransPosY,
  755.                                        SubTransWidth, SubTransHeight);
  756.     if (DrawMiddleVertLine) {
  757.     values.foreground = TransSubWinBorderPixel;
  758.     XChangeGC(XDisplay, XTransGraphContext, GCForeground, &values);
  759.  
  760.     XDrawLine(XDisplay, Win, XTransGraphContext,
  761.           SubTransWidth / 2, 0, SubTransWidth / 2, SubTransHeight);
  762.     }
  763.     if (DrawString != NULL) {
  764.     DrawText(Win, DrawString, SubTransWidth / 2, SubTransHeight / 2,
  765.          TransTextPixel);
  766.     }
  767. }
  768.  
  769. /*****************************************************************************
  770. * Set up and draw a view window.                             *
  771. *****************************************************************************/
  772. static void SetViewWindow(void)
  773. {
  774.     static int AttributeList[] = { GLX_RGBA, None };
  775.     int HasPos = FALSE;
  776.     long PrefPos[4];
  777.     XVisualInfo    *Vi;
  778.     Colormap CMap;
  779.     XSetWindowAttributes WinAttr;
  780.     Window Win;
  781.     XEvent event;
  782.  
  783.     if (sscanf(IGGlblViewPrefPos, "%ld,%ld,%ld,%ld",
  784.            &PrefPos[0], &PrefPos[1], &PrefPos[2], &PrefPos[3]) == 4)
  785.     HasPos = TRUE;
  786.     if (!HasPos) {
  787.     PrefPos[0] = PrefPos[2] = 0;
  788.     PrefPos[1] = PrefPos[3] = 500;
  789.     }
  790.     else {
  791.     PrefPos[1] -= PrefPos[0];
  792.     PrefPos[3] -= PrefPos[2];
  793.     }
  794.  
  795.     Vi = glXChooseVisual(XDisplay, DefaultScreen(XDisplay), AttributeList);
  796.     ViewCx = glXCreateContext(XDisplay, Vi, 0, GL_TRUE);
  797.     CMap = XCreateColormap(XDisplay, RootWindow(XDisplay, Vi -> screen),
  798.                Vi -> visual, AllocNone);
  799.     WinAttr.colormap = CMap;
  800.     WinAttr.border_pixel = 0;
  801.     WinAttr.event_mask = StructureNotifyMask;
  802.     ViewWin = XCreateWindow(XDisplay, RootWindow(XDisplay, Vi -> screen),
  803.                 PrefPos[0], PrefPos[2], PrefPos[1], PrefPos[3],
  804.                 0, Vi -> depth, InputOutput, Vi -> visual,
  805.                 CWBorderPixel|CWColormap|CWEventMask, &WinAttr);
  806.     XMapWindow(XDisplay, ViewWin);
  807.     XIfEvent(XDisplay, &event, WaitForNotify, (char*) ViewWin);
  808. }
  809.  
  810. /*****************************************************************************
  811. * Set up and draw a viewing window.                         *
  812. *****************************************************************************/
  813. void IGRedrawViewWindow(void)
  814. {
  815.     IPObjectStruct *PObj;
  816.     GLdouble CrntView[16];
  817.     int i, j, k;
  818.  
  819.     glXMakeCurrent(XDisplay, ViewWin, ViewCx);
  820.  
  821.     glDrawBuffer(IGGlblDoDoubleBuffer ? GL_BACK : GL_FRONT);
  822.  
  823.     /* Clear viewing area. */
  824.     glClear(GL_COLOR_BUFFER_BIT |
  825.         (IGGlblDrawSolid ? GL_DEPTH_BUFFER_BIT : 0));
  826.  
  827.     /* activate zbuffer only if we are in solid drawing mode. */
  828.     if (IGGlblDrawSolid) {
  829.     static int
  830.         UpdateLightPos = FALSE;
  831.     static GLfloat
  832.         LightPosition[4] = { 1.0, 2.0, 10.0, 0.0 },
  833.         LightAmbient[] = { 1.0, 1.0, 1.0, 1.0 },
  834.         LightDiffuse[] = { 1.0, 1.0, 1.0, 1.0 },
  835.         LightSpecular[] = { 1.0, 1.0, 1.0, 1.0 },
  836.         LModelAmbient[] = { 0.2, 0.2, 0.2, 1.0 };
  837.  
  838.     if (!UpdateLightPos) {
  839.         int i;
  840.         
  841.         for (i = 0; i < 4; i++)
  842.         LightPosition[i] = IGGlblLightSrcPos[i];
  843.         UpdateLightPos = TRUE;
  844.     }
  845.  
  846.     glLightfv(GL_LIGHT0, GL_POSITION, LightPosition);
  847.     glLightfv(GL_LIGHT0, GL_AMBIENT, LightAmbient);
  848.     glLightfv(GL_LIGHT0, GL_DIFFUSE, LightDiffuse);
  849.     glLightfv(GL_LIGHT0, GL_SPECULAR, LightSpecular);
  850.     glLightModelfv(GL_LIGHT_MODEL_AMBIENT, LModelAmbient);
  851.  
  852.     glEnable(GL_LIGHTING);
  853.     glEnable(GL_LIGHT0);
  854.     glDepthFunc(GL_LESS);
  855.     glEnable(GL_DEPTH_TEST);
  856.     glClear(GL_DEPTH_BUFFER_BIT);
  857.     }
  858.     else {
  859.     glDisable(GL_LIGHTING);
  860.     glDisable(GL_LIGHT0);
  861.     glDisable(GL_DEPTH_TEST);
  862.     }
  863.  
  864.     if (IGGlblViewMode == IG_VIEW_PERSPECTIVE) {
  865.     for (i = 0; i < 4; i++)
  866.         for (j = 0; j < 4; j++) {
  867.         CrntView[i * 4 + j] = 0;
  868.         for (k = 0; k < 4; k++)
  869.             CrntView[i * 4 + j] += IritPrsrViewMat[i][k] *
  870.                                IritPrsrPrspMat[k][j];
  871.         }
  872.     }
  873.     else {
  874.     for (i = 0; i < 4; i++)
  875.         for (j = 0; j < 4; j++)
  876.         CrntView[i * 4 + j] = IritPrsrViewMat[i][j];
  877.     }
  878.     glLoadMatrixd(CrntView);
  879.     if (APX_EQ(IGGlblZMinClip, IGGlblZMaxClip))
  880.         IGGlblZMaxClip += EPSILON;
  881.     glOrtho(-1.0, 1.0, -1.0, 1.0, IGGlblZMinClip, IGGlblZMaxClip);
  882.  
  883.     for (PObj = IGGlblDisplayList; PObj != NULL; PObj = PObj -> Pnext)
  884.     IGDrawObject(PObj);
  885.     glFlush();
  886.  
  887.     if (IGGlblDoDoubleBuffer)
  888.     glXSwapBuffers(XDisplay, ViewWin);
  889. }
  890.  
  891. /******************************************************************************
  892. * Handle X events                                  *
  893. ******************************************************************************/
  894. static IGGraphicEventType GetGraphicEvent(RealType *ChangeFactor)
  895. {
  896.     static int LastX;
  897.     int Dx;
  898.     XEvent Event;
  899.     XWindowAttributes WinAttr;
  900.  
  901.     XMapWindow(XDisplay, TransformWndw);
  902.  
  903.     while (TRUE) {
  904.     /* Maybe we have something in communication socket. */
  905.     if (!IGGlblStandAlone &&
  906.         IGReadObjectsFromSocket(IGGlblViewMode, &IGGlblDisplayList))
  907.         IGRedrawViewWindow();
  908.  
  909.     if (XPending(XDisplay)) {
  910.         XNextEvent(XDisplay, &Event);
  911.  
  912.         switch (Event.type) {
  913.         case Expose:
  914.                 /* Get rid of all Expose events in the queue. */
  915.                 while (XCheckWindowEvent(XDisplay, Event.xbutton.window,
  916.                          ExposureMask, &Event));
  917.             if (Event.xbutton.window == TransformWndw)
  918.             RedrawTransformWindow();
  919.             else if (Event.xbutton.window == ViewWndw) {
  920.             XGetWindowAttributes(XDisplay, ViewWndw, &WinAttr);
  921.             ViewWidth = WinAttr.width;
  922.             ViewHeight = WinAttr.height;
  923.             IGRedrawViewWindow();
  924.             }
  925.             break;
  926.         case ButtonPress:
  927.             LastX = Event.xbutton.x;
  928.             *ChangeFactor =
  929.             ((RealType) (LastX - SubWindowWidthState2)) /
  930.                          SubWindowWidthState2;
  931.  
  932.             if (Event.xbutton.window == ObjScrTglWndw) {
  933.             XClearWindow(XDisplay, ObjScrTglWndw);
  934.             IGGlblTransformMode =
  935.                 IGGlblTransformMode == IG_TRANS_OBJECT ?
  936.                            IG_TRANS_SCREEN :
  937.                            IG_TRANS_OBJECT;
  938.             DrawText(ObjScrTglWndw,
  939.                 IGGlblTransformMode == IG_TRANS_OBJECT ? "Object" :
  940.                                      "Screen",
  941.                 SubWindowWidthState2, SubWindowHeightState2,
  942.                 TransTextPixel);
  943.             return IG_EVENT_SCR_OBJ_TGL;
  944.             }
  945.             else if (Event.xbutton.window == PersOrthoTglWndw) {
  946.             XClearWindow(XDisplay, PersOrthoTglWndw);
  947.             IGGlblViewMode =
  948.                 IGGlblViewMode == IG_VIEW_PERSPECTIVE ?
  949.                           IG_VIEW_ORTHOGRAPHIC :
  950.                           IG_VIEW_PERSPECTIVE;
  951.             DrawText(PersOrthoTglWndw,
  952.                  IGGlblViewMode == IG_VIEW_PERSPECTIVE ?
  953.                      "Perspective" : "Orthographic",
  954.                  SubWindowWidthState2, SubWindowHeightState2,
  955.                  TransTextPixel);
  956.             return IG_EVENT_PERS_ORTHO_TGL;
  957.             }
  958.             else if (Event.xbutton.window == PersOrthoZWndw) {
  959.             return IG_EVENT_PERS_ORTHO_Z;
  960.             }
  961.             else if (Event.xbutton.window == RotateXWndw) {
  962.             return IG_EVENT_ROTATE_X;
  963.             }
  964.             else if (Event.xbutton.window == RotateYWndw) {
  965.             return IG_EVENT_ROTATE_Y;
  966.             }
  967.             else if (Event.xbutton.window == RotateZWndw) {
  968.             return IG_EVENT_ROTATE_Z;
  969.             }
  970.             else if (Event.xbutton.window == TranslateXWndw) {
  971.             return IG_EVENT_TRANSLATE_X;
  972.             }
  973.             else if (Event.xbutton.window == TranslateYWndw) {
  974.             return IG_EVENT_TRANSLATE_Y;
  975.             }
  976.             else if (Event.xbutton.window == TranslateZWndw) {
  977.             return IG_EVENT_TRANSLATE_Z;
  978.             }
  979.             else if (Event.xbutton.window == ScaleWndw) {
  980.             return IG_EVENT_SCALE;
  981.             }
  982.             else if (Event.xbutton.window == DepthCueWndw) {
  983.             XClearWindow(XDisplay, DepthCueWndw);
  984.             IGGlblDepthCue = !IGGlblDepthCue;
  985.             DrawText(DepthCueWndw,
  986.                  IGGlblDepthCue ? "Depth Cue" : "No Depth Cue",
  987.                  SubWindowWidthState2, SubWindowHeightState2,
  988.                  TransTextPixel);
  989.             return IG_EVENT_DEPTH_CUE;
  990.             }
  991.             else if (Event.xbutton.window == SaveMatrixWndw) {
  992.             return IG_EVENT_SAVE_MATRIX;
  993.             }
  994.             else if (Event.xbutton.window == PushMatrixWndw) {
  995.             return IG_EVENT_PUSH_MATRIX;
  996.             }
  997.             else if (Event.xbutton.window == PopMatrixWndw) {
  998.             return IG_EVENT_POP_MATRIX;
  999.             }
  1000.             else if (Event.xbutton.window == QuitWndw) {
  1001.             GraphicFlush();
  1002.             return IG_EVENT_QUIT;
  1003.             }
  1004.             break;
  1005.         case MotionNotify:
  1006.             /* We may get events of movement in Y which are ignored. */
  1007.             if (Event.xbutton.x - LastX == 0)
  1008.             break;
  1009.  
  1010.             *ChangeFactor = ((RealType) (Event.xbutton.x - LastX)) /
  1011.                             SubWindowWidthState2;
  1012.             LastX = Event.xbutton.x;
  1013.  
  1014.             if (Event.xbutton.window == PersOrthoZWndw) {
  1015.             return IG_EVENT_PERS_ORTHO_Z;
  1016.             }
  1017.             else if (Event.xbutton.window == RotateXWndw) {
  1018.             return IG_EVENT_ROTATE_X;
  1019.             }
  1020.             else if (Event.xbutton.window == RotateYWndw) {
  1021.             return IG_EVENT_ROTATE_Y;
  1022.             }
  1023.             else if (Event.xbutton.window == RotateZWndw) {
  1024.             return IG_EVENT_ROTATE_Z;
  1025.             }
  1026.             else if (Event.xbutton.window == TranslateXWndw) {
  1027.             return IG_EVENT_TRANSLATE_X;
  1028.             }
  1029.             else if (Event.xbutton.window == TranslateYWndw) {
  1030.             return IG_EVENT_TRANSLATE_Y;
  1031.             }
  1032.             else if (Event.xbutton.window == TranslateZWndw) {
  1033.             return IG_EVENT_TRANSLATE_Z;
  1034.             }
  1035.             else if (Event.xbutton.window == ScaleWndw) {
  1036.             return IG_EVENT_SCALE;
  1037.             }
  1038.             break;
  1039.         default:
  1040.             fprintf(stderr,
  1041.                 "x11drvs: undefined event type %d.\n", Event.type);
  1042.         }
  1043.     }
  1044.     IritSleep(10);
  1045.     }
  1046. }
  1047.  
  1048. /******************************************************************************
  1049. * Handle the event of a pop up window.                          *
  1050. ******************************************************************************/
  1051. int IGHandleState(int State, int Refresh)
  1052. {
  1053.     int UpdateView = TRUE;
  1054.  
  1055.     switch (State) {
  1056.     case IG_STATE_SCR_OBJ_TGL:
  1057.         IGGlblTransformMode = IGGlblTransformMode == IG_TRANS_OBJECT ?
  1058.                              IG_TRANS_SCREEN :
  1059.                              IG_TRANS_OBJECT;
  1060.         RedrawTransformWindow();
  1061.         UpdateView = FALSE;
  1062.         break;
  1063.     case IG_STATE_PERS_ORTHO_TGL:
  1064.         IGGlblViewMode = IGGlblViewMode == IG_VIEW_PERSPECTIVE ?
  1065.                            IG_VIEW_ORTHOGRAPHIC :
  1066.                            IG_VIEW_PERSPECTIVE;
  1067.         RedrawTransformWindow();
  1068.         break;
  1069.     case IG_STATE_DRAW_SOLID:
  1070.         IGGlblDrawSolid = !IGGlblDrawSolid;
  1071.         /* And fall thru to disable the depth cueing. */
  1072.         IGGlblDepthCue = TRUE; 
  1073.     case IG_STATE_DEPTH_CUE:
  1074.         IGGlblDepthCue = !IGGlblDepthCue;
  1075.         break;
  1076.     case IG_STATE_DOUBLE_BUFFER:
  1077.         IGGlblDoDoubleBuffer = !IGGlblDoDoubleBuffer;
  1078.         break;
  1079.     case IG_STATE_ANTI_ALIASING:
  1080.         IGGlblAntiAliasing = !IGGlblAntiAliasing;
  1081.         break;
  1082.     default:
  1083.         UpdateView = IGDefaultStateHandler(State, Refresh);
  1084.         break;
  1085.     }
  1086.  
  1087.     IGCreateStateMenu();
  1088.  
  1089.     return UpdateView;
  1090. }
  1091.  
  1092. /******************************************************************************
  1093. * Draw text centered at the given position.                      *
  1094. ******************************************************************************/
  1095. static void DrawText(char *Str, long PosX, long PosY)
  1096. {
  1097. #ifdef TTTT
  1098.     long Width = strwidth(Str);
  1099.  
  1100.     cmov2s(PosX - Width / 2, PosY - (getheight() / 2 - getdescender()));
  1101.     charstr(Str);
  1102. #endif
  1103. }
  1104.  
  1105. /****************************************************************************
  1106. * Make noise function.                                *
  1107. ****************************************************************************/
  1108. void IGIritBeep(void)
  1109. {
  1110. }
  1111.